/**
 * 工具函数
 */
//  引入字体图标的样式
require("../../fonts/iconfont.css")
/**
 * 手机号正则验证
 */
function phoneCheck(PhoneNum) {
    return /^1[3-9]\d{9}$/.test(PhoneNum) //规则写在/ /之间，以^开始以$结束
}
// 密码正则验证
function pwdCheck(pwdNum) {
    return /^[a-zA-Z]\w{5,11}$/.test(pwdNum);

}
/**
 * 错误或正确的提示
 */
function popBox(icon, tipsText) {
    let divDom = document.createElement('div')
    divDom.classList.add('module-box')
    divDom.classList.add('abs')
    divDom.classList.add('disflex')
    divDom.innerHTML = `
    <div class="module-box abs disflex">
        <div class="module-box-content tcenter fon12 colorf">
            <i class="iconfont ${icon}"></i>
            <p class="jump">${tipsText}</p>
        </div>
    </div>
`
    document.body.append(divDom)
    setTimeout(function () {
        divDom.style.display = 'none'
    }, 2001)
}

// 封装底部导航栏
function navigation(pageFlag) {
    let footer = document.querySelector('.footer')
    // let navDiv= document.createElement('div')
    // inedx run mine
    footer.innerHTML = `
        <a class="tcenter nav-link ${pageFlag==="index"?"active":""}" href="./index.html">
            <i class="iconfont icon-31shouye fon45"></i>
            <p class="fon14">首页</p>
        </a>
        <a class="tcenter nav-link ${pageFlag==="run"?"active":""}" href="./run.html">
            <i class="iconfont icon-xintiaojiankangyundongyiliaobaohuxinshuai fon45"></i>
            <p class="fon14">运动</p>
        </a>
        <a class="tcenter nav-link ${pageFlag==="circle"?"active":""}" href="./circle.html">
            <i class="iconfont icon-pintu"></i>
            <p class="fon14">圈子</p>
        </a>
        <a class="tcenter nav-link ${pageFlag==="mine"?"active":""}" href="./mine.html">
            <i class="iconfont icon-wode fon45"></i>
            <p class="fon14">我的</p>
        </a>
        `
   

}
// 运动顶部切换
function sportsNav(sportsPage){
    let header = document.querySelector('.sports-header')
    header.innerHTML = `
    <ul class="sports-ul disflex">
        <li class="sports-item ${sportsPage==="run"?"active":""}"><a href="./run.html">跑步</a></li>
        <li class="sports-item ${sportsPage==="ride"?"active":""}"><a href="./ride.html">骑行</a></li>
        <li class="sports-item ${sportsPage==="train"?"active":""}"><a href="./train.html">训练课程</a></li>
    </ul>
        `

}

// 补零
function addZero(param) {
    return param < 10 ? "0" + param : param
}

// 挂载到window对象上
window.$util = {
    phoneCheck,
    pwdCheck,
    popBox,
    navigation,
    sportsNav,
    addZero

}